//
//  BuildingInfoViewController.m
//  OutesIOS
//
//  Created by norman on 2019/1/6.
//  Copyright © 2019 norman. All rights reserved.
//

#import "BuildingInfoViewController.h"
#import "BottomActionView.h"
#import "EditorTableViewCell.h"
#import "RoomNameViewController.h"
#import "MachineSelectViewController.h"
#import <MBProgressHUD.h>
#import "ProjectData.h"
#import "IndoorEquipDataResp.h"
#import "MachineSelectTableViewCell.h"
#import "GuidData.h"
#import "IndoorEquipData.h"
#import "SNJMachineSelectViewController.h"
#import "ProjectManager.h"
#import "LoadFactorDataResp.h"
#import "UITapView.h"
#import "SelectXSViewController.h"
#import "FjpgViewController.h"
#import "TerminalTypeTableViewCell.h"
#import "SelectStep3ViewController.h"
#import "WaterEquipListViewController.h"
#import "CalcTableViewCell.h"
#import "UITapLabel.h"

#define RoomInformationCell @"RoomInformationCell"
#define CalcCell @"CalcCell"


@interface BuildingInfoViewController (){
}

@property (nonatomic,strong) BuildingData *BuildingData;
@property (nonatomic,strong) UIBarButtonItem *rightBtn;

@property (nonatomic,strong) UIView *coeffView;
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) UITextField *textField1;
@property (nonatomic,strong) UITextField *textField2;
@property (nonatomic,strong) UITextField *textField3;
@property (nonatomic,strong) UITextField *textField4;
@property (nonatomic,strong) UITextField *textField5;

@end

@implementation BuildingInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initData];
    [self setupViews];
}

/**
 *  初始化数据
 */
- (void)initData {
    if (self.currentIndex >= kHeatProject.buildings.count) {
        return;
    }
    if (self.currentIndex == kHeatProject.buildings.count - 1) {
        self.navigationItem.rightBarButtonItem = nil;
    }
    self.BuildingData = [kHeatProject.buildings objectAtIndex:self.currentIndex];
}

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark - 初始化视图
- (void)setupViews{
    self.title = @"建筑信息编辑";
    
    //自定义返回按钮
    UIBarButtonItem *returnBtn = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:self action:@selector(onReturn)];
    self.navigationItem.leftBarButtonItem = returnBtn;
    self.rightBtn = [[UIBarButtonItem alloc] initWithTitle:@"下一个" style:UIBarButtonItemStyleDone target:self action:@selector(saveAndNext)];
    self.navigationItem.rightBarButtonItem = self.rightBtn;
    if (self.currentIndex == kHeatProject.buildings.count - 1) {
        self.rightBtn.title = @"完成";
    }
    self.tableView = [[UITableView alloc] initWithFrame:[UIView frameWithOutNav] style:UITableViewStyleGrouped];
    [self.tableView registerClass:[EditorTableViewCell class] forCellReuseIdentifier:RoomInformationCell];
    [self.tableView registerClass:[CalcTableViewCell class] forCellReuseIdentifier:CalcCell];
    [self.tableView registerClass:[TerminalTypeTableViewCell class] forCellReuseIdentifier:@"ter"];
    self.tableView.backgroundColor = UIColor16(0xeeeeee);
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
}

#pragma mark - 事件响应
- (void)onReturn {
    [self updateBuildingData:^(BOOL result) {
        [self.navigationController popViewControllerAnimated:YES];
    }];
}

- (void)saveAndNext {
    if (![self validBuildData]) {
        return;
    }
    [self updateBuildingData:^(BOOL result) {
        if (result) {
            [self onNext];
        } else {
            [Tools showMessageCenter:@"保存数据失败！"];
        }
    }];
}

- (void)onNext {
    self.currentIndex++;
    if (self.currentIndex == kHeatProject.buildings.count - 1) {
        self.rightBtn.title = @"完成";
    }
    else if (self.currentIndex > kHeatProject.buildings.count - 1) {
        //完成下一步
//        if (kHeatProject.buildings == nil || kHeatProject.buildings.count == 0) {
//            [Tools showMessageCenter:@"项目中至少要有一个建筑!"];
//            return;
//        }
//        BOOL hasEquip = NO;
//        for (BuildingData *item in kHeatProject.buildings) {
//            if (![Tools isEmpty:item.equip]) {
//                hasEquip = YES;
//                break;
//            }
//        }
//        if (!hasEquip) {
//            [Tools showMessageCenter:@"项目需要选择主机设备!"];
//            return;
//        }
//        [[ProjectManager manager]goNextPage];
//        SelectStep3ViewController *view = [SelectStep3ViewController new];
//        [self.navigationController pushViewController:view animated:YES];
        [self.navigationController popViewControllerAnimated:YES];
        return;
    }
    self.BuildingData = [kHeatProject.buildings objectAtIndex:self.currentIndex];
    [self.tableView reloadData];
}

- (BOOL)validBuildData {
    if (self.BuildingData.length == 0) {
        [Tools showMessageCenter:@"建筑长度不能为0"];
        return NO;
    }
    if (self.BuildingData.width == 0) {
        [Tools showMessageCenter:@"建筑宽度不能为0"];
        return NO;
    }
    if (self.BuildingData.floor_count == 0) {
        [Tools showMessageCenter:@"建筑层数不能为0"];
        return NO;
    }
    if (self.BuildingData.floor_height == 0) {
        [Tools showMessageCenter:@"建筑高度不能为0"];
        return NO;
    }
    if (self.BuildingData.water_out_t == 0) {
        [Tools showMessageCenter:@"主机出水温度不能为0"];
        return NO;
    }
//    if (self.BuildingData.water_in_t == 0) {
//        [Tools showMessageCenter:@"主机进水温度不能为0"];
//        return NO;
//    }
    if (self.BuildingData.room_design_t == 0) {
        [Tools showMessageCenter:@"室内设计温度不能为0"];
        return NO;
    }
    if (self.BuildingData.es_building == 0) {
        // 节能建筑
        if ([Tools isEmpty:self.textField1.text] || [self.textField1.text doubleValue] == 0) {
            [Tools showMessageCenter:@"外墙传热系数不能为0"];
            return NO;
        }
        if ([Tools isEmpty:self.textField2.text] || [self.textField2.text doubleValue] == 0) {
            [Tools showMessageCenter:@"外窗传热系数不能为0"];
            return NO;
        }
        if ([Tools isEmpty:self.textField3.text] || [self.textField3.text doubleValue] == 0) {
            [Tools showMessageCenter:@"屋顶传热系数不能为0"];
            return NO;
        }
        if ([Tools isEmpty:self.textField4.text] || [self.textField4.text doubleValue] == 0) {
            [Tools showMessageCenter:@"天窗传热系数不能为0"];
            return NO;
        }
        if ([Tools isEmpty:self.textField5.text] || [self.textField5.text doubleValue] == 0) {
            [Tools showMessageCenter:@"架空楼板传热系数不能为0"];
            return NO;
        }
    }
    return YES;
}

- (void)updateBuildingData:(void (^)(BOOL))result {
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:self.BuildingData.heat_project_id forKey:@"heat_project_id"];
    [params setValue:self.BuildingData.building_id forKey:@"building_id"];
    [params setValue:self.BuildingData.building_name forKey:@"building_name"];
    [params setValue:@(self.BuildingData.building_type) forKey:@"building_type"];
    [params setValue:@(self.BuildingData.terminal_type) forKey:@"terminal_type"];
    [params setValue:@(self.BuildingData.heat_type) forKey:@"heat_type"];
    [params setValue:@(self.BuildingData.es_building) forKey:@"es_building"];
    [params setValue:@(self.BuildingData.is_regular) forKey:@"is_regular"];
    [params setValue:@(self.BuildingData.length) forKey:@"length"];
    [params setValue:@(self.BuildingData.width) forKey:@"width"];
    [params setValue:@(self.BuildingData.floor_count) forKey:@"floor_count"];
    [params setValue:@(self.BuildingData.floor_height) forKey:@"floor_height"];
    [params setValue:@(self.BuildingData.window_rate) forKey:@"window_rate"];
    [params setValue:@(self.BuildingData.room_design_t) forKey:@"room_design_t"];
    [params setValue:@(self.BuildingData.water_out_t) forKey:@"water_out_t"];
    [params setValue:@(self.BuildingData.water_in_t) forKey:@"water_in_t"];
    [params setValue:@(self.BuildingData.running_time) forKey:@"running_time"];
    [params setValue:self.BuildingData.equip forKey:@"equip"];
    [params setValue:@(self.BuildingData.quantity) forKey:@"quantity"];
    [params setValue:@(self.BuildingData.total_load) forKey:@"total_load"];
    
    if (self.BuildingData.es_building == 0) {
        [params setValue:self.textField1.text forKey:@"es_coeff1"];
        [params setValue:self.textField2.text forKey:@"es_coeff2"];
        [params setValue:self.textField3.text forKey:@"es_coeff3"];
        [params setValue:self.textField4.text forKey:@"es_coeff4"];
        [params setValue:self.textField5.text forKey:@"es_coeff5"];
    }
   
    [HttpClient postWithUrl:HTTP_POST_HEAT_PROJECT_BUILDING_UPDATE token:[AccountManager manager].token paramDic:params resultClass:[BuildingData class] success:^(BuildingData *obj) {
        self.BuildingData.total_load = obj.total_load;
        if (self.BuildingData.es_building == 0) {
            self.BuildingData.es_coeff1 = [self.textField1.text doubleValue];
            self.BuildingData.es_coeff2 = [self.textField2.text doubleValue];
            self.BuildingData.es_coeff3 = [self.textField3.text doubleValue];
            self.BuildingData.es_coeff4 = [self.textField4.text doubleValue];
            self.BuildingData.es_coeff5 = [self.textField5.text doubleValue];
        }
        if (self.buildingInfoChangedBlock != nil) {
            self.buildingInfoChangedBlock();
        }
        result(YES);
    } failure:^(NSError *error) {
        result(NO);
    }];
}

#pragma mark - tableView显示设置数据
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 5;
    } else if (section == 1) {
         return 5;
    } else if (section == 2) {
        return 3;
    } else {
        if ([Tools isEmpty:self.BuildingData.equip]) {
            return 2;
        }
        return 3;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    EditorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:RoomInformationCell];
    cell.accessoryType = UITableViewCellAccessoryNone;
    [cell setEditorText:@""];
    cell.TextFiledEditingEndBlock = nil;
    cell.editorView.enabled = YES;
    UITableViewCell *Selectcell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"SelectArea_Cell"];
    Selectcell.textLabel.textColor = CM_TABLE_TITLE_COLOR;
    Selectcell.detailTextLabel.textColor = CM_TABLE_INFO_COLOR;
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        //建筑名称
        cell.accessoryType = UITableViewCellAccessoryNone;
        
        [cell setTitleStr:@"建筑名称" andColor:BSBlackTextColor andHintStr:@"请输入建筑名称" andInputViewIsHidden:NO andInfoStr:nil andUnit:nil];
        [cell setEditorText:[NSString stringWithFormat:@"%@", self.BuildingData.building_name]];
        [cell setKeyboardType:UIKeyboardTypeDefault];
        cell.TextFiledEditingEndBlock = ^(NSString *value){
            if (value != nil && value.length > 0) {
                self.BuildingData.building_name = [NSString stringWithString:value];
            } else {
                [Tools showMessageCenter:@"建筑名称不能为空！"];
            }
        };
    }
//    else if (indexPath.section == 0 && indexPath.row == 1) {
//        Selectcell.textLabel.text = @"建筑性质";
//        if (self.BuildingData.building_type == 0) {
//            Selectcell.detailTextLabel.text = @"公建";
//        } else if (self.BuildingData.building_type == 1) {
//            Selectcell.detailTextLabel.text = @"民建";
//        } else if (self.BuildingData.building_type == 1) {
//            Selectcell.detailTextLabel.text = @"厂房";
//        } else {
//            Selectcell.detailTextLabel.text = @"其他";
//        }
//        Selectcell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//        return Selectcell;
//    }
    else if (indexPath.section == 0 && indexPath.row == 1) {
        Selectcell.textLabel.text = @"末端类型";
        if (self.BuildingData.terminal_type == 0) {
            Selectcell.detailTextLabel.text = @"风盘";
        } else if (self.BuildingData.terminal_type == 1) {
            Selectcell.detailTextLabel.text = @"地暖";
        } else if (self.BuildingData.terminal_type == 2) {
            Selectcell.detailTextLabel.text = @"暖气片";
        } else {
            Selectcell.detailTextLabel.text = @"其他";
        }
        Selectcell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return Selectcell;
    } else if (indexPath.section == 0 && indexPath.row == 2) {
        Selectcell.textLabel.text = @"采暖分类";
        if (self.BuildingData.heat_type == 0) {
            Selectcell.detailTextLabel.text = @"舒适性";
        } else {
            Selectcell.detailTextLabel.text = @"工艺性";
        }
        Selectcell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return Selectcell;
    } else if (indexPath.section == 0 && indexPath.row == 4) {
        Selectcell.textLabel.text = @"节能建筑";
        if (self.BuildingData.es_building == 0) {
            Selectcell.detailTextLabel.text = @"否";
        } else {
            Selectcell.detailTextLabel.text = @"是";
        }
        Selectcell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return Selectcell;
    } else if (indexPath.section == 0 && indexPath.row == 3) {
        Selectcell.textLabel.text = @"建筑外形";
        if (self.BuildingData.is_regular == 1) {
            Selectcell.detailTextLabel.text = @"规则";
        } else {
            Selectcell.detailTextLabel.text = @"不规则";
        }
        Selectcell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return Selectcell;
    }
    else if (indexPath.section == 1 && indexPath.row == 0) {
        [cell setTitleStr:@"建筑长" andColor:nil andHintStr:@"请输入建筑长度" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"m"];
        if (self.BuildingData.length > 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%d", (int)self.BuildingData.length]];
        }
        [cell setKeyboardType:UIKeyboardTypeNumberPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.length = [value doubleValue];
            }
        };
    } else if (indexPath.section == 1 && indexPath.row == 1) {
        [cell setTitleStr:@"建筑宽" andColor:nil andHintStr:@"请输入建筑宽度" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"m"];
        if (self.BuildingData.width > 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%d", (int)self.BuildingData.width]];
        }
        [cell setKeyboardType:UIKeyboardTypeNumberPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.width = [value doubleValue];
            }
        };
    } else if (indexPath.section == 1 && indexPath.row == 2) {
        [cell setTitleStr:@"建筑层高" andColor:nil andHintStr:@"请输入建筑层高" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"m"];
        if (self.BuildingData.floor_height > 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.floor_height]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.floor_height = [value doubleValue];
            }
        };
    } else if (indexPath.section == 1 && indexPath.row == 3) {
        [cell setTitleStr:@"建筑层数" andColor:nil andHintStr:@"请输入建筑层数" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"层"];
        if (self.BuildingData.floor_count > 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%d", (int)self.BuildingData.floor_count]];
        }
        [cell setKeyboardType:UIKeyboardTypeNumberPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value intValue] > 0) {
                self.BuildingData.floor_count = [value intValue];
            }
        };
    } else if (indexPath.section == 1 && indexPath.row == 4) {
        [cell setTitleStr:@"窗墙比" andColor:nil andHintStr:@"请输入建筑窗墙比" andInputViewIsHidden:NO andInfoStr:nil andUnit:@""];
        if (self.BuildingData.window_rate > 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.window_rate]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.window_rate = [value doubleValue];
            }
        };
    } else if (indexPath.section == 2 && indexPath.row == 0) {
        [cell setTitleStr:@"每日运行时间" andColor:nil andHintStr:@"请输入建筑每日运行时间" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"小时"];
        if (self.BuildingData.running_time > 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%d", (int)self.BuildingData.running_time]];
        }
        [cell setKeyboardType:UIKeyboardTypeNumberPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.running_time = [value doubleValue];
            }
        };
    } else if (indexPath.section == 2 && indexPath.row == 1) {
        [cell setTitleStr:@"室内设计温度" andColor:nil andHintStr:@"请输入建筑室内设计温度" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"℃"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    } else if (indexPath.section == 2 && indexPath.row == 2) {
        [cell setTitleStr:@"主机出水温度" andColor:nil andHintStr:@"请输入主机出水温度" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"℃"];
        if (self.BuildingData.water_out_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.water_out_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
//        cell.TextFiledValueBlock = ^(NSString *value){
//            if ([value doubleValue] >= 20 && [value doubleValue] <= 60) {
//                self.BuildingData.water_out_t = [value doubleValue];
//            } else {
//                [Tools showMessageCenter:@"主机出水温度范围为20℃～60℃"];
//            }
//        };
        @weakObj(cell)
        cell.TextFiledEditingEndBlock = ^(NSString *value) {
            if ([value doubleValue] < 20 && [value doubleValue] <= 60) {
                self.BuildingData.water_out_t = 20;
                Weakcell.editorView.text = @"20";
                [Tools showMessageCenter:@"主机出水温度不能小于20℃～60℃"];
            } else  if ([value doubleValue] > 60) {
                [Tools showMessageCenter:@"主机出水温度不能大于60℃"];
                Weakcell.editorView.text = @"60";
                self.BuildingData.water_out_t = [value doubleValue];
            } else {
                self.BuildingData.water_out_t = [value doubleValue];
            }
        };
    }
//    else if (indexPath.section == 1 && indexPath.row == 9) {
//        [cell setTitleStr:@"主机回水温度" andColor:nil andHintStr:@"请输入主机回水温度" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"℃"];
//        if (self.BuildingData.water_in_t != 0) {
//            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.water_in_t]];
//        }
//
//        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
//        cell.TextFiledValueBlock = ^(NSString *value){
//            if ([value doubleValue] > 0) {
//                self.BuildingData.water_in_t = [value doubleValue];
//            }
//        };
//    }
    else if (indexPath.section == 3 && indexPath.row == 0) {
        CalcTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CalcCell];
        if (self.BuildingData.total_load > 0) {
            [cell setLoadData:[NSString stringWithFormat:@"%0.1f", self.BuildingData.total_load]];
        } else {
            [cell setLoadData:@""];
        }
        cell.calcClicked = ^{
            if (![self validBuildData]) {
                return;
            }
            [MBProgressHUD showMessage:@"数据提交中..." toView:self.view];
            [self updateBuildingData:^(BOOL result) {
                [MBProgressHUD hideHUDForView:self.view];
                if (result) {
                    [self.tableView reloadRowsAtIndexPaths:indexPathObj(0, 3) withRowAnimation:UITableViewRowAnimationAutomatic];
                } else {
                    [Tools showMessageCenter:@"保存数据失败！"];
                }
            }];
        };
        return cell;
//        [cell setTitleStr:@"计算总负荷" andColor:CM_ORANGE_COLOR andHintStr:@"请输入建筑总负荷" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"kW"];
//        [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.total_load]];
//        cell.editorView.enabled = NO;
//        cell.userInteractionEnabled = YES;
    } else if (indexPath.section == 3  && indexPath.row == 1) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        [cell setTitleStr:@"主机" andColor:BSBlackTextColor andHintStr:nil andInputViewIsHidden:YES andInfoStr:nil andUnit:nil];
        [cell setNavigationHint:@"手动选择"];
    } else {
        [cell setTitleStr:self.BuildingData.equip andColor:nil andHintStr:nil andInputViewIsHidden:NO andInfoStr:nil andUnit:@"台"];
        [cell setEditorText:[NSString stringWithFormat:@"%d", self.BuildingData.quantity]];
        cell.editorView.enabled = NO;
    }
    return cell;
}

-(NSArray *)rightButtons {
    NSMutableArray *rightUtilityButtons = [NSMutableArray new];
    [rightUtilityButtons sw_addUtilityButtonWithColor:[UIColor redColor] title:@"删除"];
    return rightUtilityButtons;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section == 0 && indexPath.row == 1) {
        [self selectTerminalType];
    } else if (indexPath.section == 0 && indexPath.row == 2) {
        [self selectHeatType];
    } else if (indexPath.section == 0 && indexPath.row == 4) {
        [self selectIsEsBuilding];
    } else if (indexPath.section == 0 && indexPath.row == 3) {
        [self selectBuildingCoeff];
    } else if (indexPath.section == 3 && indexPath.row == 0) {
        if (![self validBuildData]) {
            return;
        }
        [MBProgressHUD showMessage:@"数据提交中..." toView:self.view];
        [self updateBuildingData:^(BOOL result) {
            [MBProgressHUD hideHUDForView:self.view];
            if (result) {
                [self.tableView reloadRowsAtIndexPaths:indexPathObj(0, 3) withRowAnimation:UITableViewRowAnimationAutomatic];
            } else {
                [Tools showMessageCenter:@"保存数据失败！"];
            }
        }];
    } else if (indexPath.section == 3 && indexPath.row == 1) {
        if (self.BuildingData.total_load > 0) {
            WaterEquipListViewController *vc = [WaterEquipListViewController new];
            if (![Tools isEmpty:self.BuildingData.equip]) {
                vc.selectedGuid = self.BuildingData.equip;
            }
            vc.machineSelectedBlock = ^(NSDictionary * _Nonnull equip, double total_load) {
                self.BuildingData.equip = [equip objectForKey:@"Model"];
                self.BuildingData.quantity = [[equip objectForKey:@"count"] intValue];
                self.BuildingData.total_load = total_load;
                [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:3]  withRowAnimation:UITableViewRowAnimationAutomatic];
            };
            vc.building_id = self.BuildingData.building_id;
            [self.navigationController pushViewController:vc animated:YES];
        } else {
            [Tools showMessageCenter:@"请先计算负荷！"];
        }
//        if (![self validBuildData]) {
//            return;
//        }
//        [MBProgressHUD showMessage:@"数据提交中..." toView:self.view];
//        [self updateBuildingData:^(BOOL result) {
//            [MBProgressHUD hideHUDForView:self.view];
//            if (result) {
//                WaterEquipListViewController *vc = [WaterEquipListViewController new];
//                if (![Tools isEmpty:self.BuildingData.equip]) {
//                    vc.selectedGuid = self.BuildingData.equip;
//                }
//                vc.machineSelectedBlock = ^(NSDictionary * _Nonnull equip, double total_load) {
//                    self.BuildingData.equip = [equip objectForKey:@"Model"];
//                    self.BuildingData.quantity = [[equip objectForKey:@"count"] intValue];
//                    self.BuildingData.total_load = total_load;
//                    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1]  withRowAnimation:UITableViewRowAnimationAutomatic];
//                };
//                vc.building_id = self.BuildingData.building_id;
//                [self.navigationController pushViewController:vc animated:YES];
//            } else {
//                [Tools showMessageCenter:@"保存数据失败！"];
//            }
//        }];
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
//    if (indexPath.section == 1) {
//        if (indexPath.row == 2) {
//            static NSString *identifier = @"qxssyktMachineSelectCell";
//            MachineSelectTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
//            if (cell == nil) {
//                cell = [[MachineSelectTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
//            }
//            return [cell getHeigh];
//        }
//    }
    static NSString *identifier = @"RoomInformationCell";
    EditorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[EditorTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
    }
    return [cell getHeight];
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, CGFLOAT_MIN)];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    if (section == 0) {
        if (self.BuildingData.es_building == 0) {
            return [self setupCoeffView];
        } else {
            return [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, DEFAULT_SECTION_HEIGHT)];
        }
    }
    return [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, DEFAULT_SECTION_HEIGHT)];
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 0) {
        //节能建筑
        if (self.BuildingData.es_building == 0) {
             return 240 + DEFAULT_SECTION_HEIGHT;
        } else {
             return DEFAULT_SECTION_HEIGHT;
        }
    }
    return DEFAULT_SECTION_HEIGHT;
}

- (UIView *)setupCoeffView {
    if (self.coeffView == nil) {
        self.coeffView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, 240 + DEFAULT_SECTION_HEIGHT)];
        self.coeffView.backgroundColor = [UIColor whiteColor];
        
        UITapLabel *lb1 = [[UITapLabel alloc]init];
        lb1.text = @"外墙传热系数";
        lb1.width = [Tools sizeOfSingleLineText:lb1.text withSize:15].width + 5;
        lb1.height = [Tools sizeOfSingleLineText:lb1.text withSize:15].height;
        [lb1 addTargetsBlock:^(id obj) {
            [self.textField1 becomeFirstResponder];
        }];
        lb1.font = [UIFont systemFontOfSize:15];
        lb1.textColor = CM_TABLE_TITLE_COLOR;
        lb1.x = 30;
        lb1.centerY = 20;
        [self.coeffView addSubview:lb1];
        
        UILabel *lb11 = [UILabel labelSingleLineFontSize:13 content:@"W/(㎡·K)"];
        lb11.textColor = BSBlackTextColor;
        lb11.x = kScreen_Width - lb11.width - CELL_PADDING_RIGHT;
        lb11.centerY = 20;
        [self.coeffView addSubview:lb11];
        
        self.textField1 = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lb1.frame) + 5, lb1.y, lb11.x - CGRectGetMaxX(lb1.frame) - 10, lb1.height)];
        self.textField1.textColor = CM_TABLE_DETAIL_COLOR;
        self.textField1.font = [UIFont systemFontOfSize:kListTitleFontSize];
        self.textField1.keyboardType = UIKeyboardTypeDecimalPad;
        self.textField1.textAlignment = NSTextAlignmentRight;
        [self.textField1 addTarget:self action:@selector(textFieldChanged:) forControlEvents:UIControlEventEditingChanged];
        self.textField1.inputAccessoryView = [self addToolbar:1];
        if (self.BuildingData.es_coeff1 > 0) {
            self.textField1.text = [NSString stringWithFormat:@"%0.2f", self.BuildingData.es_coeff1];
        }
        [self.coeffView addSubview:self.textField1];
        
        UIView *line1 = [[UIView alloc]initWithFrame:CGRectMake(lb1.x, 40, kScreen_Width - lb1.x, 1)];
        line1.backgroundColor =  UIColor16(0xEEEEEE);
        [self.coeffView addSubview:line1];
        
        UITapLabel *lb2 = [[UITapLabel alloc]init];
        lb2.text = @"外窗传热系数";
        lb2.width = [Tools sizeOfSingleLineText:lb2.text withSize:15].width + 5;
        lb2.height = [Tools sizeOfSingleLineText:lb2.text withSize:15].height;
        [lb2 addTargetsBlock:^(id obj) {
            [self.textField2 becomeFirstResponder];
        }];
        lb2.font = [UIFont systemFontOfSize:15];
        lb2.textColor = CM_TABLE_TITLE_COLOR;
        lb2.x = 30;
        lb2.centerY = 60;
        [self.coeffView addSubview:lb2];
        
        UILabel *lb22 = [UILabel labelSingleLineFontSize:13 content:@"W/(㎡·K)"];
        lb22.textColor = BSBlackTextColor;
        lb22.x = kScreen_Width - lb22.width - CELL_PADDING_RIGHT;
        lb22.centerY = 60;
        [self.coeffView addSubview:lb22];
        
        self.textField2 = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lb2.frame) + 5, lb2.y, lb22.x - CGRectGetMaxX(lb2.frame) - 10, lb2.height)];
        self.textField2.textColor = CM_TABLE_DETAIL_COLOR;
        self.textField2.font = [UIFont systemFontOfSize:kListTitleFontSize];
        self.textField2.keyboardType = UIKeyboardTypeDecimalPad;
        self.textField2.textAlignment = NSTextAlignmentRight;
        [self.textField2 addTarget:self action:@selector(textFieldChanged:) forControlEvents:UIControlEventEditingChanged];
        self.textField2.inputAccessoryView = [self addToolbar:2];
        if (self.BuildingData.es_coeff2 > 0) {
            self.textField2.text = [NSString stringWithFormat:@"%0.2f", self.BuildingData.es_coeff2];
        }
        [self.coeffView addSubview:self.textField2];
        
        UIView *line2 = [[UIView alloc]initWithFrame:CGRectMake(lb2.x, 80, kScreen_Width - lb2.x, 1)];
        line2.backgroundColor =  UIColor16(0xEEEEEE);
        [self.coeffView addSubview:line2];
        
        UITapLabel *lb3 = [[UITapLabel alloc]init];
        lb3.text = @"屋顶传热系数";
        lb3.width = [Tools sizeOfSingleLineText:lb3.text withSize:15].width + 5;
        lb3.height = [Tools sizeOfSingleLineText:lb3.text withSize:15].height;
        [lb3 addTargetsBlock:^(id obj) {
            [self.textField3 becomeFirstResponder];
        }];
        lb3.font = [UIFont systemFontOfSize:15];
        lb3.textColor = CM_TABLE_TITLE_COLOR;
        lb3.x = 30;
        lb3.centerY = 100;
        [self.coeffView addSubview:lb3];
        
        UILabel *lb33 = [UILabel labelSingleLineFontSize:13 content:@"W/(㎡·K)"];
        lb33.textColor = BSBlackTextColor;
        lb33.x = kScreen_Width - lb33.width - CELL_PADDING_RIGHT;
        lb33.centerY = 100;
        [self.coeffView addSubview:lb33];
        
        self.textField3 = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lb3.frame) + 5, lb3.y, lb33.x - CGRectGetMaxX(lb3.frame) - 10, lb3.height)];
        self.textField3.textColor = CM_TABLE_DETAIL_COLOR;
        self.textField3.font = [UIFont systemFontOfSize:kListTitleFontSize];
        self.textField3.keyboardType = UIKeyboardTypeDecimalPad;
        self.textField3.textAlignment = NSTextAlignmentRight;
        [self.textField3 addTarget:self action:@selector(textFieldChanged:) forControlEvents:UIControlEventEditingChanged];
        self.textField3.inputAccessoryView = [self addToolbar:3];
        if (self.BuildingData.es_coeff3 > 0) {
            self.textField3.text = [NSString stringWithFormat:@"%0.2f", self.BuildingData.es_coeff3];
        }
        [self.coeffView addSubview:self.textField3];
        
        UIView *line3 = [[UIView alloc]initWithFrame:CGRectMake(lb3.x, 120, kScreen_Width - lb3.x, 1)];
        line3.backgroundColor =  UIColor16(0xEEEEEE);
        [self.coeffView addSubview:line3];
        
        UITapLabel *lb4 = [[UITapLabel alloc]init];
        lb4.text = @"天窗传热系数";
        lb4.width = [Tools sizeOfSingleLineText:lb4.text withSize:15].width + 5;
        lb4.height = [Tools sizeOfSingleLineText:lb4.text withSize:15].height;
        [lb4 addTargetsBlock:^(id obj) {
            [self.textField4 becomeFirstResponder];
        }];
        lb4.font = [UIFont systemFontOfSize:15];
        lb4.textColor = CM_TABLE_TITLE_COLOR;
        lb4.x = 30;
        lb4.centerY = 140;
        [self.coeffView addSubview:lb4];
        
        UILabel *lb44 = [UILabel labelSingleLineFontSize:13 content:@"W/(㎡·K)"];
        lb44.textColor = BSBlackTextColor;
        lb44.x = kScreen_Width - lb44.width - CELL_PADDING_RIGHT;
        lb44.centerY = 140;
        [self.coeffView addSubview:lb44];
        
        self.textField4 = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lb4.frame) + 5, lb4.y, lb44.x - CGRectGetMaxX(lb4.frame) - 10, lb4.height)];
        self.textField4.textColor = CM_TABLE_DETAIL_COLOR;
        self.textField4.font = [UIFont systemFontOfSize:kListTitleFontSize];
        self.textField4.keyboardType = UIKeyboardTypeDecimalPad;
        self.textField4.textAlignment = NSTextAlignmentRight;
        [self.textField4 addTarget:self action:@selector(textFieldChanged:) forControlEvents:UIControlEventEditingChanged];
        self.textField4.inputAccessoryView = [self addToolbar:4];
        if (self.BuildingData.es_coeff4 > 0) {
            self.textField4.text = [NSString stringWithFormat:@"%0.2f", self.BuildingData.es_coeff4];
        }
        [self.coeffView addSubview:self.textField4];
        
        UIView *line4 = [[UIView alloc]initWithFrame:CGRectMake(lb4.x, 160, kScreen_Width - lb4.x, 1)];
        line4.backgroundColor =  UIColor16(0xEEEEEE);
        [self.coeffView addSubview:line4];
        
        UITapLabel *lb5 = [[UITapLabel alloc]init];
        lb5.text = @"架空楼板传热系数";
        lb5.width = [Tools sizeOfSingleLineText:lb5.text withSize:15].width + 5;
        lb5.height = [Tools sizeOfSingleLineText:lb5.text withSize:15].height;
        [lb5 addTargetsBlock:^(id obj) {
            [self.textField5 becomeFirstResponder];
        }];
        lb5.font = [UIFont systemFontOfSize:15];
        lb5.textColor = CM_TABLE_TITLE_COLOR;
        lb5.x = 30;
        lb5.centerY = 180;
        [self.coeffView addSubview:lb5];
        
        UILabel *lb55 = [UILabel labelSingleLineFontSize:13 content:@"W/(㎡·K)"];
        lb55.textColor = BSBlackTextColor;
        lb55.x = kScreen_Width - lb55.width - CELL_PADDING_RIGHT;
        lb55.centerY = 180;
        [self.coeffView addSubview:lb55];
        
        self.textField5 = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lb5.frame) + 5, lb5.y, lb55.x - CGRectGetMaxX(lb5.frame) - 10, lb5.height)];
        self.textField5.textColor = CM_TABLE_DETAIL_COLOR;
        self.textField5.font = [UIFont systemFontOfSize:kListTitleFontSize];
        self.textField5.keyboardType = UIKeyboardTypeDecimalPad;
        self.textField5.textAlignment = NSTextAlignmentRight;
        [self.textField5 addTarget:self action:@selector(textFieldChanged:) forControlEvents:UIControlEventEditingChanged];
        self.textField5.inputAccessoryView = [self addToolbar:5];
        if (self.BuildingData.es_coeff5 > 0) {
            self.textField5.text = [NSString stringWithFormat:@"%0.2f", self.BuildingData.es_coeff5];
        }
        [self.coeffView addSubview:self.textField5];
        
        UIView *line5 = [[UIView alloc]initWithFrame:CGRectMake(lb5.x, 200, kScreen_Width - lb5.x, 1)];
        line5.backgroundColor =  UIColor16(0xEEEEEE);
        [self.coeffView addSubview:line5];

        UITapLabel *lb6 = [[UITapLabel alloc]init];
        lb6.text = @"如何设置传热系数？";
        lb6.width = [Tools sizeOfSingleLineText:lb6.text withSize:13].width + 5;
        lb6.height = [Tools sizeOfSingleLineText:lb6.text withSize:13].height;
        [lb6 addTargetsBlock:^(id obj) {
            NSString *msg = @"混凝土墙（普通砂浆/绝热砂浆）——3（2.7/1.6）\n\n180砖墙（普通砂浆/绝热砂浆）——3（2.7/1.6）\n\n240砖墙（普通砂浆/绝热砂浆）——2.7（2.4/1.5）\n\n370砖墙（普通砂浆/绝热砂浆）——1.8（1.5/1.0）\n\n玻璃/窗(单层/双）——6.4/4.0\n\n大棚薄膜（单/充气）——6.8/4.0\n\n夹心苯板（5cm/10cm）——0.6/0.35\n\n阳光板（6cm/8cm/10cm/16cm）——3.5/3.3/3.0/2.7\n\n※如非上述维护结构，请咨询设计施工方。";
            CSToastStyle *style = [[CSToastStyle alloc] initWithDefaultStyle];
            style.messageFont = [UIFont systemFontOfSize:13];
//            [kWindow makeToast:msg duration:10.0 position:CSToastPositionCenter];
            [kWindow makeToast:msg duration:10.0 position:CSToastPositionCenter style:style];
        }];
        lb6.font = [UIFont systemFontOfSize:13];
        lb6.textColor = CM_BLUE_COLOR;
        lb6.centerX = kScreen_Width/2;
        lb6.centerY = 220;
        [self.coeffView addSubview:lb6];
        
        UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 240, kScreen_Width, DEFAULT_SECTION_HEIGHT)];
        v.backgroundColor = CM_TABLE_BG_COLOR;
        [self.coeffView addSubview:v];
    } else {
        if (self.BuildingData.es_coeff1 > 0) {
            self.textField1.text = [NSString stringWithFormat:@"%0.2f", self.BuildingData.es_coeff1];
        } else {
            self.textField1.text = @"";
        }
        if (self.BuildingData.es_coeff2 > 0) {
            self.textField2.text = [NSString stringWithFormat:@"%0.2f", self.BuildingData.es_coeff2];
        } else {
            self.textField2.text = @"";
        }
        if (self.BuildingData.es_coeff3 > 0) {
            self.textField3.text = [NSString stringWithFormat:@"%0.2f", self.BuildingData.es_coeff3];
        } else {
            self.textField3.text = @"";
        }
        if (self.BuildingData.es_coeff4 > 0) {
            self.textField4.text = [NSString stringWithFormat:@"%0.2f", self.BuildingData.es_coeff4];
        } else {
            self.textField4.text = @"";
        }
        if (self.BuildingData.es_coeff5 > 0) {
            self.textField5.text = [NSString stringWithFormat:@"%0.2f", self.BuildingData.es_coeff5];
        } else {
            self.textField5.text = @"";
        }
    }
    return self.coeffView;
}

- (UIToolbar *)addToolbar:(NSInteger)tag
{
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 35)];
    toolbar.tintColor = [UIColor blueColor];
    toolbar.backgroundColor = [UIColor colorWithRed:160/255.0 green:160/255.0 blue:160/255.0 alpha:1.0];
    toolbar.tag = tag;
    UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(textFieldDone:)];
    bar.tag = tag;
    toolbar.items = @[space, bar];
    return toolbar;
}



- (void)textFieldChanged:(id)textField {
    
}

- (void)textFieldDone:(UIBarButtonItem*)bar {
    NSInteger tag = bar.tag;
    if (tag == 1) {
        [self.textField1 resignFirstResponder];
    } else if (tag == 2) {
        [self.textField2 resignFirstResponder];
    } else if (tag == 3) {
        [self.textField3 resignFirstResponder];
    } else if (tag == 4) {
        [self.textField4 resignFirstResponder];
    } else if (tag == 5) {
        [self.textField5 resignFirstResponder];
    }
}



#pragma mark - 滑动按钮代理协议
/**
 *  右侧滑动按钮点击事件
 *
 *  @param cell  单元cell
 *  @param index 下标
 */
-(void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index{
    switch (index) {
        case 0:{
//            [self deleteRoomEquip:cell.tag];
            break;
        }
        default:
            break;
    }
    [cell hideUtilityButtonsAnimated:YES];
}


/**
 *  滑动的时候把其他的隐藏掉
 *
 *  @param cell cell
 *
 *  @return 隐藏其他的cell
 */
-(BOOL)swipeableTableViewCellShouldHideUtilityButtonsOnSwipe:(SWTableViewCell *)cell{
    return YES;
}

- (void)selectTerminalType {
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"选择末端类型" message: nil preferredStyle:UIAlertControllerStyleActionSheet];
    [alertController addAction: [UIAlertAction actionWithTitle:@"风盘" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.terminal_type = 0;
        self.BuildingData.water_out_t = 50;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(2, 2) withRowAnimation:UITableViewRowAnimationAutomatic];
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(1, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"地暖" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.terminal_type = 1;
        self.BuildingData.water_out_t = 45;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(2, 2) withRowAnimation:UITableViewRowAnimationAutomatic];
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(1, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"暖气片" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.terminal_type = 2;
        self.BuildingData.water_out_t = 55;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(2, 2) withRowAnimation:UITableViewRowAnimationAutomatic];
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(1, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"其他" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.terminal_type = 3;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(1, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
    [self presentViewController: alertController animated: YES completion: nil];
}

- (void)selectHeatType {
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"选择采暖类型" message: nil preferredStyle:UIAlertControllerStyleActionSheet];
    [alertController addAction: [UIAlertAction actionWithTitle:@"舒适性采暖" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.heat_type = 0;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(2, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"工艺性采暖" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.heat_type = 1;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(2, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
    [self presentViewController: alertController animated: YES completion: nil];
}

- (void)selectIsEsBuilding {
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"是否是节能建筑" message: nil preferredStyle:UIAlertControllerStyleActionSheet];
    [alertController addAction: [UIAlertAction actionWithTitle:@"是" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.es_building = 1;
//        [self.tableView reloadRowsAtIndexPaths:indexPathObj(3, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"否" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.es_building = 0;
        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
    [self presentViewController: alertController animated: YES completion: nil];
}

- (void)selectBuildingCoeff {
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"建筑外形" message: nil preferredStyle:UIAlertControllerStyleActionSheet];
    [alertController addAction: [UIAlertAction actionWithTitle:@"规则" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.is_regular = 1;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(3, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"不规则" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.is_regular = 0;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(3, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
    [self presentViewController: alertController animated: YES completion: nil];
}

- (void)selectBuildingType {
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"选择建筑性质" message: nil preferredStyle:UIAlertControllerStyleActionSheet];
    [alertController addAction: [UIAlertAction actionWithTitle:@"公建" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.building_type = 0;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(1, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"民建" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.building_type = 1;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(1, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"厂房" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.building_type = 2;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(1, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"其他" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.building_type = 13;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(1, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
    [self presentViewController: alertController animated: YES completion: nil];
}




/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
